﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jalal.Library.Data;
using System.Data;
using Jalal.Library.Utility;
using System.Data.Common;

namespace BCGC.DAL
{
    public class PostTagData
    {
        public static int CreatePostTag(String tag, int tagWaight)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreatePostTag";

            dataMiner.AddParameter(command, "@Tag", DbType.String, 100, ParameterDirection.Input, tag);
            dataMiner.AddParameter(command, "@TagWeight", DbType.Int32, 0, ParameterDirection.Input, tagWaight);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static bool UpdatePostTag(int postTagID,String tag, int tagWaight)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdatePostTag";

            dataMiner.AddParameter(command, "@PostTagID", DbType.Int32, 0, ParameterDirection.Input, postTagID);
            dataMiner.AddParameter(command, "@Tag", DbType.String, 100, ParameterDirection.Input, tag);
            dataMiner.AddParameter(command, "@TagWeight", DbType.Int32, 0, ParameterDirection.Input, tagWaight);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (bool)CommonUtility.FilterNull(id, typeof(bool));
        }

        public static DataTable GetByTagName(String tagname)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetPostTagByTagName";
            dataMiner.AddParameter(command, "@TagName", DbType.String, 100, ParameterDirection.Input, tagname);
            return dataMiner.GetListData(command);
        }

        public static DataTable GetAllPostTag()
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetAllPostTag";
            return dataMiner.GetListData(command);
        }

        public static bool DeletePostTag(int tagID)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeletePostTag";

            dataMiner.AddParameter(command, "@PostTagID", DbType.Int32, 0, ParameterDirection.Input, tagID);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (bool)CommonUtility.FilterNull(id, typeof(bool));
        }
    }
}
